package com.happy3w.ssp.schoolmatehome.controller;

import com.happy3w.ssp.schoolmatehome.interceptor.AttributeKeys;
import com.happy3w.ssp.schoolmatehome.service.auth.TheUserDetail;
import com.happy3w.ssp.schoolmatehome.service.note.NoteSearcher;
import com.happy3w.ssp.schoolmatehome.service.note.NoteSummary;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/recommend")
public class RecommendController {
    private final NoteSearcher noteSearcher;

    @GetMapping("note")
    public ResponseEntity<List<NoteSummary>> recommendNotes(@RequestAttribute(AttributeKeys.USER_DETAIL) TheUserDetail userDetail,
                                                            @RequestParam(required = false, name = "query") String query,
                                                            @RequestParam(required = false, name = "page", defaultValue = "0") int page,
                                                            @RequestParam(required = false, name = "size", defaultValue = "20") int size) {
        List<NoteSummary> notes = noteSearcher.findRecommendNotes(userDetail.getUser(), query, page, size);
        return ResponseEntity.ok(notes);
    }
}
